package com.baizhi.service.impl;

import com.baizhi.entity.User;
import com.baizhi.mapper.UserMapper;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean login(String name, String password) {
        User user = userMapper.selectUsers(name);
        if(user!=null&&user.getPassword().equals(password)){
            return true;
        }
        return false;
    }

    @Override
    public boolean register(String name, String pwd1, String pwd2) {
        User user1 = userMapper.selectUsers(name);
        if(user1==null&&pwd1.equals(pwd2)){
            User user=new User(null,name,pwd1);
            userMapper.insertUser(user);
            return true;
        }else{
            return false;

        }

    }
}
